package com.kuiandjie.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kuiandjie.entity.Message;
import com.kuiandjie.util.DBHelp;
import com.kuiandjie.util.RowMapper;

public class MessageDao {
	private DBHelp<Message> db = new DBHelp<Message>();
	
	@SuppressWarnings("unused")
	private class MessageMap implements RowMapper<Message>{

		@Override
		public Message mapperRow(ResultSet rs) throws SQLException {
			Message msg = new Message();
			msg.setContent(rs.getString("content"));
			msg.setCreateTime(rs.getString("createtime"));
			msg.setEmployeeId(rs.getInt("employeeid"));
			msg.setProjectId(rs.getInt("projectid"));
			
			return msg;
		}
	}
	
	public int addMsg(Message msg) {
		String sql = "INSERT INTO t_message (content, createtime, employeeid, projectid) VALUES (?, ?, ?, ?)";
		return db.getAutoKey(sql, msg.getContent(), msg.getCreateTime(), msg.getEmployeeId(), msg.getProjectId());
	}
}
